/*
	Copyright (c) 2008, Grant Jones <grant@podtronics.com>.
	All rights reserved.

	Redistribution and use in source and binary forms, with or
	without modification, are permitted provided that the following
	conditions are met:

		Redistributions of source code must retain the above copyright
		notice, this list of conditions and the following disclaimer.
		
		Redistributions in binary form must reproduce the above copyright
		notice, this list of conditions and the following disclaimer in
		the documentation and/or other materials provided with the
		distribution.
		
		Neither the name of the gxjones.com nor the names of its
		contributors may be used to endorse or promote products derived
		from this software without specific prior written permission.
	
	THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
	"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
	LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
	FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
	COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
	INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
	(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
	SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
	OF THE POSSIBILITY OF SUCH DAMAGE.
	
	http://www.opensource.org/licenses/bsd-license.php
*/

/*
 *  asb_request.h
 *  scatterd
 *
 *  Created by Grant Jones on 3/14/08.
 *
 */

#ifndef ASDB_REQUEST_H
#define ASDB_REQUEST_H

#define ASDB_ACCESS_KEY		"AWSAccessKeyId"
#define ASDB_ACCESS_KEY_SZ	14
#define ASDB_SECRET_KEY		"SECRETE ACCESS KEY"
#define ASDB_SECRET_KEY_SZ	18

#include "asdb_main.h"

typedef struct 
{
	cmapStruct *strout;
	strmapStruct *req_params;
} asdb_req_ctx;


void asdb_req_test();

/*!
	@function asdb_req_mkval
	@abstract convience function to make allocate a edb_value_t structure
	@discussion
	@param pool
	@param z edb_value_t.z
	@param n edb_value_t.n
	@result a edb_value_t structure allocated from pool
*/
edb_value_t *asdb_req_mkval( mempool_t *pool, const char *z, size_t n );
edb_value_t *asdb_req_mkval2( mempool_t *pool, const char *z );

edb_value_t *asdb_req_mktimestamp( mempool_t *pool );





/*!
	@function asdb_req_sortparams
	@abstract creates a list of the params in alphabetical order,
	          ignoring case
	@discussion
	@param req_params the key/value pairs to be sorted
	@result a newly allocated cmap from req_params mempool, the map
	        value field will be populated with the param name
			pointer
*/
cmapStruct *asdb_req_sortparams( strmapStruct *req_params );

/*!
	@function asdb_req_create_sig
	@abstract creates the signature based on the access info and request parameters
	@discussion req_params should not contain the Signature param
	@param pool
	@param access_info
	@param req_params
	@result a base-64 encoded signature allocated from pool
*/
char *asdb_req_create_sig( mempool_t *pool, strmapStruct *access_info, strmapStruct *req_params );

void asdb_req_do_next( simpledb_t *sdb );
int asdb_queue_store( simpledb_t *sdb, const char *domain, size_t domain_sz, cmapStruct *affected_item );
int asdb_req_queue_getall( simpledb_t *sdb, const char *domain, size_t domain_sz );
int asdb_req_queue_get( simpledb_t *sdb, const char *domain, size_t domain_sz, const char *item, size_t item_sz );

int asdb_req_queue_domain_create( simpledb_t *sdb, const char *domain, size_t domain_sz );
int asdb_req_queue_domain_delete( simpledb_t *sdb, const char *domain, size_t domain_sz );

#endif